class Menu
  
  attr_accessor :menu
  
  def initialize menuu=[]
    @menu = menuu
  end
  
  def menu
    return  @menu = [] if @menu.nil?
    @menu
  end

  def allow_menu2 (items, roles)
    res = []
    items.each do |item|
      if item.roles.empty? || !(item.roles & roles).empty?
        current = item.clone
        current.submenu = allow_menu2(current.submenu, roles) unless current.submenu.empty?
        res << current
      end
    end
    res
  end
  
  def allow_menu roles = []    
    allow_menu2(menu, roles)
  end
  
end